home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / aplictns / xscheme2 / part03 < prev    next >
Encoding:
Internet Message Format  |  1990-04-14  |  59.8 KB

  1. Path: xanth!cs.odu.edu!Amiga-Request
  2. From: Amiga-Request@cs.odu.edu (Amiga Sources/Binaries Moderator)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v90i141: XScheme 0.20 - an object-oriented scheme, Part03/07
  5. Message-ID: <12211@xanth.cs.odu.edu>
  6. Date: 14 Apr 90 21:10:25 GMT
  7. Sender: tadguy@cs.odu.edu
  8. Reply-To: rusty@fe2o3.UUCP (Rusty Haddock)
  9. Lines: 2332
  10. Approved: tadguy@cs.odu.edu (Tad Guy)
  11. X-Mail-Submissions-To: Amiga@cs.odu.edu
  12. X-Post-Discussions-To: comp.sys.amiga
  13.  
  14. Submitted-by: rusty@fe2o3.UUCP (Rusty Haddock)
  15. Posting-number: Volume 90, Issue 141
  16. Archive-name: applications/xscheme-0.20/part03
  17.  
  18. #!/bin/sh
  19. # This is a shell archive.  Remove anything before this line, then unpack
  20. # it by saving it into a file and typing "sh file".  To overwrite existing
  21. # files, type "sh file -c".  You can also feed this as standard input via
  22. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  23. # will see the following message at the end:
  24. #        "End of archive 3 (of 7)."
  25. # Contents:  Src/xscheme.h Src/xsdmem.c Src/xsftab.c Src/xsmath.c
  26. # Wrapped by tadguy@xanth on Sat Apr 14 17:07:24 1990
  27. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  28. if test -f 'Src/xscheme.h' -a "${1}" != "-c" ; then 
  29.   echo shar: Will not clobber existing file \"'Src/xscheme.h'\"
  30. else
  31. echo shar: Extracting \"'Src/xscheme.h'\" \(13100 characters\)
  32. sed "s/^X//" >'Src/xscheme.h' <<'END_OF_FILE'
  33. X/* xscheme.h - xscheme definitions */
  34. X/*    Copyright (c) 1988, by David Michael Betz
  35. X    All Rights Reserved
  36. X    Permission is granted for unrestricted non-commercial use    */
  37. X
  38. X/* system specific definitions */
  39. X#define AZTEC_AMIGA
  40. X
  41. X#include <stdio.h>
  42. X#include <ctype.h>
  43. X#include <setjmp.h>
  44. X
  45. X/* FORWARD    type of a forward declaration () */
  46. X/* LOCAL    type of a local function (static) */
  47. X/* AFMT        printf format for addresses ("%x") */
  48. X/* OFFTYPE    number the size of an address (int) */
  49. X/* FIXTYPE    data type for fixed point numbers (long) */
  50. X/* ITYPE    fixed point input conversion routine type (long atol()) */
  51. X/* ICNV        fixed point input conversion routine (atol) */
  52. X/* IFMT        printf format for fixed point numbers ("%ld") */
  53. X/* FLOTYPE    data type for floating point numbers (float) */
  54. X/* FFMT        printf format for floating point numbers (%.15g) */
  55. X
  56. X/* for the Lightspeed C compiler - Macintosh */
  57. X#ifdef LSC
  58. X#define AFMT        "%lx"
  59. X#define OFFTYPE        long
  60. X#define NIL        (void *)0
  61. X#define MACINTOSH
  62. X#endif
  63. X
  64. X/* for the UNIX System V C compiler */
  65. X#ifdef UNIX
  66. X#endif
  67. X
  68. X/* for the Aztec C compiler - Amiga */
  69. X#ifdef AZTEC_AMIGA
  70. X#define AFMT        "%lx"
  71. X#define OFFTYPE        long
  72. X#define FLOTYPE        double
  73. X#endif
  74. X
  75. X/* for the Mark Williams C compiler - Atari ST */
  76. X#ifdef MWC
  77. X#define AFMT        "%lx"
  78. X#define OFFTYPE        long
  79. X#endif
  80. X
  81. X/* for the Microsoft C 5.0 compiler */
  82. X#ifdef MSC
  83. X#define AFMT        "%lx"
  84. X#define OFFTYPE        long
  85. X#define INSEGMENT(n,s)    (((OFFTYPE)(n) >> 16) == ((OFFTYPE)(s) >> 16))
  86. X#define VCOMPARE(f,s,t)    ((LVAL huge *)(f) + (s) < (LVAL huge *)(t))
  87. X/* #define MSDOS -- MSC 5.0 defines this automatically */
  88. X#endif
  89. X
  90. X/* for the Turbo C compiler */
  91. X#ifdef _TURBOC_
  92. X#define AFMT        "%lx"
  93. X#define OFFTYPE        long
  94. X#define INSEGMENT(n,s)    (((OFFTYPE)(n) >> 16) == ((OFFTYPE)(s) >> 16))
  95. X#define VCOMPARE(f,s,t)    ((LVAL huge *)(f) + (s) < (LVAL huge *)(t))
  96. X#define MSDOS
  97. X#endif
  98. X
  99. X/* size of each type of memory segment */
  100. X#ifndef NSSIZE
  101. X#define NSSIZE    4000    /* number of nodes per node segment */
  102. X#endif
  103. X#ifndef VSSIZE
  104. X#define VSSIZE    10000    /* number of LVAL's per vector segment */
  105. X#endif
  106. X
  107. X/* default important definitions */
  108. X#ifndef FORWARD
  109. X#define FORWARD
  110. X#endif
  111. X#ifndef LOCAL
  112. X#define LOCAL        static
  113. X#endif
  114. X#ifndef AFMT
  115. X#define AFMT        "%x"
  116. X#endif
  117. X#ifndef OFFTYPE
  118. X#define OFFTYPE        int
  119. X#endif
  120. X#ifndef FIXTYPE
  121. X#define FIXTYPE        long
  122. X#endif
  123. X#ifndef ITYPE
  124. X#define ITYPE        long atol()
  125. X#endif
  126. X#ifndef ICNV
  127. X#define ICNV(n)        atol(n)
  128. X#endif
  129. X#ifndef IFMT
  130. X#define IFMT        "%ld"
  131. X#endif
  132. X#ifndef FLOTYPE
  133. X#define FLOTYPE        double
  134. X#endif
  135. X#ifndef FFMT
  136. X#define FFMT        "%.15g"
  137. X#endif
  138. X#ifndef SFIXMIN
  139. X#define SFIXMIN        -1048576
  140. X#define SFIXMAX        1048575
  141. X#endif
  142. X#ifndef INSEGMENT
  143. X#define INSEGMENT(n,s)    ((n) >= &(s)->ns_data[0] \
  144. X                      && (n) <  &(s)->ns_data[0] + (s)->ns_size)
  145. X#endif
  146. X#ifndef VCOMPARE
  147. X#define VCOMPARE(f,s,t)    ((f) + (s) < (t))
  148. X#endif
  149. X
  150. X/* useful definitions */
  151. X#define TRUE    1
  152. X#define FALSE    0
  153. X#ifndef NIL
  154. X#define NIL    (LVAL)0
  155. X#endif
  156. X
  157. X/* program limits */
  158. X#define STRMAX        100        /* maximum length of a string constant */
  159. X#define HSIZE        199        /* symbol hash table size */
  160. X#define SAMPLE        100        /* control character sample rate */
  161. X
  162. X/* stack manipulation macros */
  163. X#define check(n)    { if (xlsp - (n) < xlstkbase) xlstkover(); }
  164. X#define cpush(v)    { if (xlsp > xlstkbase) push(v); else xlstkover(); }
  165. X#define push(v)        (*--xlsp = (v))
  166. X#define pop()        (*xlsp++)
  167. X#define top()        (*xlsp)
  168. X#define settop(v)    (*xlsp = (v))
  169. X#define drop(n)        (xlsp += (n))
  170. X
  171. X/* argument list parsing macros */
  172. X#define xlgetarg()    (testarg(nextarg()))
  173. X#define xllastarg()    {if (xlargc != 0) xltoomany();}
  174. X#define xlpoprest()    {xlsp += xlargc;}
  175. X#define testarg(e)    (moreargs() ? (e) : xltoofew())
  176. X#define typearg(tp)    (tp(*xlsp) ? nextarg() : xlbadtype(*xlsp))
  177. X#define nextarg()    (--xlargc, *xlsp++)
  178. X#define moreargs()    (xlargc > 0)
  179. X
  180. X/* macros to get arguments of a particular type */
  181. X#define xlgacons()    (testarg(typearg(consp)))
  182. X#define xlgalist()    (testarg(typearg(listp)))
  183. X#define xlgasymbol()    (testarg(typearg(symbolp)))
  184. X#define xlgastring()    (testarg(typearg(stringp)))
  185. X#define xlgaobject()    (testarg(typearg(objectp)))
  186. X#define xlgafixnum()    (testarg(typearg(fixp)))
  187. X#define xlganumber()    (testarg(typearg(numberp)))
  188. X#define xlgachar()    (testarg(typearg(charp)))
  189. X#define xlgavector()    (testarg(typearg(vectorp)))
  190. X#define xlgaport()    (testarg(typearg(portp)))
  191. X#define xlgaiport()    (testarg(typearg(iportp)))
  192. X#define xlgaoport()    (testarg(typearg(oportp)))
  193. X#define xlgaclosure()    (testarg(typearg(closurep)))
  194. X#define xlgaenv()    (testarg(typearg(envp)))
  195. X
  196. X/* node types */
  197. X#define FREE        0
  198. X#define CONS        1
  199. X#define SYMBOL        2
  200. X#define FIXNUM        3
  201. X#define FLONUM        4
  202. X#define STRING        5
  203. X#define OBJECT        6
  204. X#define PORT        7
  205. X#define VECTOR        8
  206. X#define CLOSURE        9
  207. X#define METHOD        10
  208. X#define CODE        11
  209. X#define SUBR        12
  210. X#define XSUBR        13
  211. X#define CSUBR        14
  212. X#define CONTINUATION    15
  213. X#define CHAR        16
  214. X#define PROMISE        17
  215. X#define ENV        18
  216. X
  217. X/* node flags */
  218. X#define MARK        1
  219. X#define LEFT        2
  220. X
  221. X/* port flags */
  222. X#define PF_INPUT    1
  223. X#define PF_OUTPUT    2
  224. X#define PF_BINARY    4
  225. X
  226. X/* new node access macros */
  227. X#define ntype(x)    ((OFFTYPE)(x) & 1 ? FIXNUM : (x)->n_type)
  228. X
  229. X/* macro to determine if a non-nil value is a pointer */
  230. X#define ispointer(x)    (((OFFTYPE)(x) & 1) == 0)
  231. X
  232. X/* type predicates */                   
  233. X#define atom(x)        ((x) == NIL || ntype(x) != CONS)
  234. X#define null(x)        ((x) == NIL)
  235. X#define listp(x)    ((x) == NIL || ntype(x) == CONS)
  236. X#define numberp(x)    ((x) && ntype(x) == FIXNUM || ntype(x) == FLONUM)
  237. X#define boundp(x)    (getvalue(x) != s_unbound)
  238. X#define iportp(x)    (portp(x) && (getpflags(x) & PF_INPUT) != 0)
  239. X#define oportp(x)    (portp(x) && (getpflags(x) & PF_OUTPUT) != 0)
  240. X
  241. X/* basic type predicates */                   
  242. X#define consp(x)    ((x) && ntype(x) == CONS)
  243. X#define stringp(x)    ((x) && ntype(x) == STRING)
  244. X#define symbolp(x)    ((x) && ntype(x) == SYMBOL)
  245. X#define portp(x)    ((x) && ntype(x) == PORT)
  246. X#define objectp(x)    ((x) && ntype(x) == OBJECT)
  247. X#define fixp(x)        ((x) && ntype(x) == FIXNUM)
  248. X#define floatp(x)    ((x) && ntype(x) == FLONUM)
  249. X#define vectorp(x)    ((x) && ntype(x) == VECTOR)
  250. X#define closurep(x)    ((x) && ntype(x) == CLOSURE)
  251. X#define codep(x)    ((x) && ntype(x) == CODE)
  252. X#define methodp(x)    ((x) && ntype(x) == METHOD)
  253. X#define subrp(x)    ((x) && ntype(x) == SUBR)
  254. X#define xsubrp(x)    ((x) && ntype(x) == XSUBR)
  255. X#define charp(x)    ((x) && ntype(x) == CHAR)
  256. X#define promisep(x)    ((x) && ntype(x) == PROMISE)
  257. X#define envp(x)        ((x) && ntype(x) == ENV)
  258. X#define booleanp(x)    ((x) == NIL || ntype(x) == BOOLEAN)
  259. X
  260. X/* cons access macros */
  261. X#define car(x)        ((x)->n_car)
  262. X#define cdr(x)        ((x)->n_cdr)
  263. X#define rplaca(x,y)    ((x)->n_car = (y))
  264. X#define rplacd(x,y)    ((x)->n_cdr = (y))
  265. X
  266. X/* symbol access macros */
  267. X#define getvalue(x)     ((x)->n_vdata[0])
  268. X#define setvalue(x,v)     ((x)->n_vdata[0] = (v))
  269. X#define getpname(x)     ((x)->n_vdata[1])
  270. X#define setpname(x,v)     ((x)->n_vdata[1] = (v))
  271. X#define getplist(x)     ((x)->n_vdata[2])
  272. X#define setplist(x,v)     ((x)->n_vdata[2] = (v))
  273. X#define SYMSIZE        3
  274. X
  275. X/* vector access macros */
  276. X#define getsize(x)    ((x)->n_vsize)
  277. X#define getelement(x,i)    ((x)->n_vdata[i])
  278. X#define setelement(x,i,v) ((x)->n_vdata[i] = (v))
  279. X
  280. X/* object access macros */
  281. X#define getclass(x)    ((x)->n_vdata[1])
  282. X#define setclass(x,v)    ((x)->n_vdata[1] = (v))
  283. X#define getivar(x,i)    ((x)->n_vdata[i])
  284. X#define setivar(x,i,v)    ((x)->n_vdata[i] = (v))
  285. X
  286. X/* promise access macros */
  287. X#define getpproc(x)    ((x)->n_car)
  288. X#define setpproc(x,v)    ((x)->n_car = (v))
  289. X#define getpvalue(x)    ((x)->n_cdr)
  290. X#define setpvalue(x,v)    ((x)->n_cdr = (v))
  291. X
  292. X/* closure access macros */
  293. X#define getcode(x)    ((x)->n_car)
  294. X#define getenv(x)    ((x)->n_cdr)
  295. X
  296. X/* code access macros */
  297. X#define getbcode(x)        ((x)->n_vdata[0])
  298. X#define setbcode(x,v)        ((x)->n_vdata[0] = (v))
  299. X#define getcname(x)        ((x)->n_vdata[1])
  300. X#define setcname(x,v)        ((x)->n_vdata[1] = (v))
  301. X#define getvnames(x)        ((x)->n_vdata[2])
  302. X#define setvnames(x,v)        ((x)->n_vdata[2] = (v))
  303. X#define FIRSTLIT        3
  304. X
  305. X/* fixnum/flonum/character access macros */
  306. X#define getfixnum(x)    ((OFFTYPE)(x) & 1 ? getsfixnum(x) : (x)->n_int)
  307. X#define getflonum(x)    ((x)->n_flonum)
  308. X#define getchcode(x)    ((x)->n_chcode)
  309. X
  310. X/* small fixnum access macros */
  311. X#define cvsfixnum(x)    ((LVAL)(((OFFTYPE)x << 1) | 1))
  312. X#define getsfixnum(x)    ((FIXTYPE)((OFFTYPE)(x) >> 1))
  313. X
  314. X/* string access macros */
  315. X#define getstring(x)    ((unsigned char *)(x)->n_vdata)
  316. X#define getslength(x)    ((x)->n_vsize)
  317. X
  318. X/* iport/oport access macros */
  319. X#define getfile(x)    ((x)->n_fp)
  320. X#define setfile(x,v)    ((x)->n_fp = (v))
  321. X#define getsavech(x)    ((x)->n_savech)
  322. X#define setsavech(x,v)    ((x)->n_savech = (v))
  323. X#define getpflags(x)    ((x)->n_pflags)
  324. X#define setpflags(x,v)    ((x)->n_pflags = (v))
  325. X
  326. X/* subr access macros */
  327. X#define getsubr(x)    ((x)->n_subr)
  328. X#define getoffset(x)    ((x)->n_offset)
  329. X
  330. X/* list node */
  331. X#define n_car        n_info.n_xlist.xl_car
  332. X#define n_cdr        n_info.n_xlist.xl_cdr
  333. X
  334. X/* integer node */
  335. X#define n_int        n_info.n_xint.xi_int
  336. X
  337. X/* flonum node */
  338. X#define n_flonum    n_info.n_xflonum.xf_flonum
  339. X
  340. X/* character node */
  341. X#define n_chcode    n_info.n_xchar.xc_chcode
  342. X
  343. X/* string node */
  344. X#define n_str        n_info.n_xstr.xst_str
  345. X#define n_strlen    n_info.n_xstr.xst_length
  346. X
  347. X/* file pointer node */
  348. X#define n_fp        n_info.n_xfptr.xf_fp
  349. X#define n_savech    n_info.n_xfptr.xf_savech
  350. X#define n_pflags    n_info.n_xfptr.xf_pflags
  351. X
  352. X/* vector/object node */
  353. X#define n_vsize        n_info.n_xvect.xv_size
  354. X#define n_vdata        n_info.n_xvect.xv_data
  355. X
  356. X/* subr node */
  357. X#define n_subr        n_info.n_xsubr.xs_subr
  358. X#define n_offset    n_info.n_xsubr.xs_offset
  359. X
  360. X/* node structure */
  361. Xtypedef struct node {
  362. X    char n_type;        /* type of node */
  363. X    char n_flags;        /* flag bits */
  364. X    union ninfo {         /* value */
  365. X    struct xlist {        /* list node (cons) */
  366. X        struct node *xl_car;    /* the car pointer */
  367. X        struct node *xl_cdr;    /* the cdr pointer */
  368. X    } n_xlist;
  369. X    struct xint {        /* integer node */
  370. X        FIXTYPE xi_int;        /* integer value */
  371. X    } n_xint;
  372. X    struct xflonum {    /* flonum node */
  373. X        FLOTYPE xf_flonum;        /* flonum value */
  374. X    } n_xflonum;
  375. X    struct xchar {        /* character node */
  376. X        int xc_chcode;        /* character code */
  377. X    } n_xchar;
  378. X    struct xstr {        /* string node */
  379. X        int xst_length;        /* string length */
  380. X        unsigned char *xst_str;    /* string pointer */
  381. X    } n_xstr;
  382. X    struct xfptr {        /* file pointer node */
  383. X        FILE *xf_fp;        /* the file pointer */
  384. X        short xf_savech;        /* lookahead character for input files */
  385. X        short xf_pflags;        /* port flags */
  386. X    } n_xfptr;
  387. X    struct xvect {        /* vector node */
  388. X        int xv_size;        /* vector size */
  389. X        struct node **xv_data;    /* vector data */
  390. X    } n_xvect;
  391. X    struct xsubr {        /* subr/fsubr node */
  392. X        struct node *(*xs_subr)();    /* function pointer */
  393. X        int xs_offset;        /* offset into funtab */
  394. X    } n_xsubr;
  395. X    } n_info;
  396. X} NODE,*LVAL;
  397. X
  398. X/* memory allocator definitions */
  399. X
  400. X/* macros to compute the size of a segment */
  401. X#define nsegsize(n) (sizeof(NSEGMENT)+((n)-1)*sizeof(struct node))
  402. X#define vsegsize(n) (sizeof(VSEGMENT)+((n)-1)*sizeof(LVAL))
  403. X
  404. X/* macro to convert a byte size to a word size */
  405. X#define btow_size(n)    (((n) + sizeof(LVAL) - 1) / sizeof(LVAL))
  406. X
  407. X/* node segment structure */
  408. Xtypedef struct nsegment {
  409. X    struct nsegment *ns_next;    /* next node segment */
  410. X    unsigned int ns_size;    /* number of nodes in this segment */
  411. X    struct node ns_data[1];    /* segment data */
  412. X} NSEGMENT;
  413. X
  414. X/* vector segment structure */
  415. Xtypedef struct vsegment {
  416. X    struct vsegment *vs_next;    /* next vector segment */
  417. X    LVAL *vs_free;        /* next free location in this segment */
  418. X    LVAL *vs_top;        /* top of segment (plus one) */
  419. X    LVAL vs_data[1];        /* segment data */
  420. X} VSEGMENT;
  421. X
  422. X/* function definition structure */
  423. Xtypedef struct {
  424. X    char *fd_name;    /* function name */
  425. X    LVAL (*fd_subr)();    /* function entry point */
  426. X} FUNDEF;
  427. X
  428. X/* external variables */
  429. Xextern LVAL *xlstkbase;     /* base of value stack */
  430. Xextern LVAL *xlstktop;        /* top of value stack */
  431. Xextern LVAL *xlsp;            /* value stack pointer */
  432. Xextern int xlargc;        /* argument count for current call */
  433. X
  434. X/* external routine declarations */
  435. Xextern LVAL cons();        /* (cons x y) */
  436. Xextern LVAL xlenter();        /* enter a symbol */
  437. Xextern LVAL xlgetprop();    /* get the value of a property */
  438. Xextern LVAL cvsymbol();     /* convert a string to a symbol */
  439. Xextern LVAL cvstring();     /* convert a string */
  440. Xextern LVAL cvfixnum();     /* convert a fixnum */
  441. Xextern LVAL cvflonum();           /* convert a flonum */
  442. Xextern LVAL cvchar();         /* convert a character */
  443. Xextern LVAL cvclosure();    /* convert code and an env to a closure */
  444. Xextern LVAL cvmethod();        /* convert code and an env to a method */
  445. Xextern LVAL cvsubr();        /* convert a function into a subr */
  446. Xextern LVAL cvport();        /* convert a file pointer to an input port */
  447. Xextern LVAL cvpromise();    /* convert a procedure to a promise */
  448. Xextern LVAL newstring();    /* create a new string */
  449. Xextern LVAL newobject();    /* create a new object */
  450. Xextern LVAL newvector();    /* create a new vector */
  451. Xextern LVAL newcode();        /* create a new code object */
  452. Xextern LVAL newcontinuation();    /* create a new continuation object */
  453. Xextern LVAL newframe();        /* create a new environment frame */
  454. Xextern LVAL newnode();        /* create a new node */
  455. Xextern LVAL xltoofew();        /* report "too few arguments" */
  456. Xextern LVAL xlbadtype();    /* report "wrong argument type" */
  457. Xextern LVAL curinput();        /* get the current input port */
  458. Xextern LVAL curoutput();    /* get the current output port */
  459. END_OF_FILE
  460. if test 13100 -ne `wc -c <'Src/xscheme.h'`; then
  461.     echo shar: \"'Src/xscheme.h'\" unpacked with wrong size!
  462. fi
  463. # end of 'Src/xscheme.h'
  464. fi
  465. if test -f 'Src/xsdmem.c' -a "${1}" != "-c" ; then 
  466.   echo shar: Will not clobber existing file \"'Src/xsdmem.c'\"
  467. else
  468. echo shar: Extracting \"'Src/xsdmem.c'\" \(15137 characters\)
  469. sed "s/^X//" >'Src/xsdmem.c' <<'END_OF_FILE'
  470. X/* xsdmem.c - xscheme dynamic memory management routines */
  471. X/*    Copyright (c) 1988, by David Michael Betz
  472. X    All Rights Reserved
  473. X    Permission is granted for unrestricted non-commercial use    */
  474. X
  475. X#include "xscheme.h"
  476. X
  477. X/* virtual machine registers */
  478. XLVAL xlfun=NIL;        /* current function */
  479. XLVAL xlenv=NIL;        /* current environment */
  480. XLVAL xlval=NIL;        /* value of most recent instruction */
  481. XLVAL *xlsp=NULL;    /* value stack pointer */
  482. X
  483. X/* stack limits */
  484. XLVAL *xlstkbase=NULL;    /* base of value stack */
  485. XLVAL *xlstktop=NULL;    /* top of value stack (actually, one beyond) */
  486. X
  487. X/* variables shared with xsimage.c */
  488. XFIXTYPE total=0;    /* total number of bytes of memory in use */
  489. XFIXTYPE gccalls=0;    /* number of calls to the garbage collector */
  490. X
  491. X/* node space */
  492. XNSEGMENT *nsegments=NULL;    /* list of node segments */
  493. XNSEGMENT *nslast=NULL;        /* last node segment */
  494. Xint nscount=0;            /* number of node segments */
  495. XFIXTYPE nnodes=0;        /* total number of nodes */
  496. XFIXTYPE nfree=0;        /* number of nodes in free list */
  497. XLVAL fnodes=NIL;        /* list of free nodes */
  498. X
  499. X/* vector (and string) space */
  500. XVSEGMENT *vsegments=NULL;    /* list of vector segments */
  501. XVSEGMENT *vscurrent=NULL;    /* current vector segment */
  502. Xint vscount=0;            /* number of vector segments */
  503. XLVAL *vfree=NULL;        /* next free location in vector space */
  504. XLVAL *vtop=NULL;        /* top of vector space */
  505. X
  506. X/* external variables */
  507. Xextern LVAL s_unbound;        /* *UNBOUND* symbol */
  508. Xextern LVAL obarray;        /* *OBARRAY* symbol */
  509. Xextern LVAL default_object;    /* default object */
  510. Xextern LVAL eof_object;        /* eof object */
  511. Xextern LVAL true;        /* truth value */
  512. X
  513. X/* external routines */
  514. Xextern unsigned char *calloc();
  515. X
  516. X/* forward declarations */
  517. XFORWARD LVAL allocnode();
  518. XFORWARD LVAL allocvector();
  519. X
  520. X/* cons - construct a new cons node */
  521. XLVAL cons(x,y)
  522. X  LVAL x,y;
  523. X{
  524. X    LVAL nnode;
  525. X
  526. X    /* get a free node */
  527. X    if ((nnode = fnodes) == NIL) {
  528. X    check(2);
  529. X    push(x);
  530. X    push(y);
  531. X    findmemory();
  532. X    if ((nnode = fnodes) == NIL)
  533. X        xlabort("insufficient node space");
  534. X    drop(2);
  535. X    }
  536. X
  537. X    /* unlink the node from the free list */
  538. X    fnodes = cdr(nnode);
  539. X    --nfree;
  540. X
  541. X    /* initialize the new node */
  542. X    nnode->n_type = CONS;
  543. X    rplaca(nnode,x);
  544. X    rplacd(nnode,y);
  545. X
  546. X    /* return the new node */
  547. X    return (nnode);
  548. X}
  549. X
  550. X/* newframe - create a new environment frame */
  551. XLVAL newframe(parent,size)
  552. X  LVAL parent; int size;
  553. X{
  554. X    LVAL frame;
  555. X    frame = cons(newvector(size),parent);
  556. X    frame->n_type = ENV;
  557. X    return (frame);
  558. X}
  559. X
  560. X/* cvstring - convert a string to a string node */
  561. XLVAL cvstring(str)
  562. X  unsigned char *str;
  563. X{
  564. X    LVAL val;
  565. X    val = newstring(strlen(str)+1);
  566. X    strcpy(getstring(val),str);
  567. X    return (val);
  568. X}
  569. X
  570. X/* cvsymbol - convert a string to a symbol */
  571. XLVAL cvsymbol(pname)
  572. X  unsigned char *pname;
  573. X{
  574. X    LVAL val;
  575. X    val = allocvector(SYMBOL,SYMSIZE);
  576. X    cpush(val);
  577. X    setvalue(val,s_unbound);
  578. X    setpname(val,cvstring(pname));
  579. X    setplist(val,NIL);
  580. X    return (pop());
  581. X}
  582. X
  583. X/* cvfixnum - convert an integer to a fixnum node */
  584. XLVAL cvfixnum(n)
  585. X  FIXTYPE n;
  586. X{
  587. X    LVAL val;
  588. X    if (n >= SFIXMIN && n <= SFIXMAX)
  589. X    return (cvsfixnum(n));
  590. X    val = allocnode(FIXNUM);
  591. X    val->n_int = n;
  592. X    return (val);
  593. X}
  594. X
  595. X/* cvflonum - convert a floating point number to a flonum node */
  596. XLVAL cvflonum(n)
  597. X  FLOTYPE n;
  598. X{
  599. X    LVAL val;
  600. X    val = allocnode(FLONUM);
  601. X    val->n_flonum = n;
  602. X    return (val);
  603. X}
  604. X
  605. X/* cvchar - convert an integer to a character node */
  606. XLVAL cvchar(ch)
  607. X  int ch;
  608. X{
  609. X    LVAL val;
  610. X    val = allocnode(CHAR);
  611. X    val->n_chcode = ch;
  612. X    return (val);
  613. X}
  614. X
  615. X/* cvclosure - convert code and an environment to a closure */
  616. XLVAL cvclosure(code,env)
  617. X  LVAL code,env;
  618. X{
  619. X    LVAL val;
  620. X    val = cons(code,env);
  621. X    val->n_type = CLOSURE;
  622. X    return (val);
  623. X}
  624. X
  625. X/* cvpromise - convert a procedure to a promise */
  626. XLVAL cvpromise(code,env)
  627. X  LVAL code,env;
  628. X{
  629. X    LVAL val;
  630. X    val = cons(cvclosure(code,env),NIL);
  631. X    val->n_type = PROMISE;
  632. X    return (val);
  633. X}
  634. X
  635. X/* cvmethod - convert code and an environment to a method */
  636. XLVAL cvmethod(code,class)
  637. X  LVAL code,class;
  638. X{
  639. X    LVAL val;
  640. X    val = cons(code,class);
  641. X    val->n_type = METHOD;
  642. X    return (val);
  643. X}
  644. X
  645. X/* cvsubr - convert a function to a subr/xsubr */
  646. XLVAL cvsubr(type,fcn,offset)
  647. X  int type; LVAL (*fcn)(); int offset;
  648. X{
  649. X    LVAL val;
  650. X    val = allocnode(type);
  651. X    val->n_subr = fcn;
  652. X    val->n_offset = offset;
  653. X    return (val);
  654. X}
  655. X
  656. X/* cvport - convert a file pointer to an port */
  657. XLVAL cvport(fp,flags)
  658. X  FILE *fp; int flags;
  659. X{
  660. X    LVAL val;
  661. X    val = allocnode(PORT);
  662. X    setfile(val,fp);
  663. X    setsavech(val,'\0');
  664. X    setpflags(val,flags);
  665. X    return (val);
  666. X}
  667. X
  668. X/* newvector - allocate and initialize a new vector */
  669. XLVAL newvector(size)
  670. X  int size;
  671. X{
  672. X    return (allocvector(VECTOR,size));
  673. X}
  674. X
  675. X/* newstring - allocate and initialize a new string */
  676. XLVAL newstring(size)
  677. X  int size;
  678. X{
  679. X    LVAL val;
  680. X    val = allocvector(STRING,btow_size(size));
  681. X    val->n_vsize = size;
  682. X    return (val);
  683. X}
  684. X
  685. X/* newcode - create a new code object */
  686. XLVAL newcode(nlits)
  687. X  int nlits;
  688. X{
  689. X    return (allocvector(CODE,nlits));
  690. X}
  691. X
  692. X/* newcontinuation - create a new continuation object */
  693. XLVAL newcontinuation(size)
  694. X  int size;
  695. X{
  696. X    return (allocvector(CONTINUATION,size));
  697. X}
  698. X
  699. X/* newobject - allocate and initialize a new object */
  700. XLVAL newobject(cls,size)
  701. X  LVAL cls; int size;
  702. X{
  703. X    LVAL val;
  704. X    val = allocvector(OBJECT,size+2); /* class, ivars */
  705. X    setclass(val,cls);
  706. X    return (val);
  707. X}
  708. X
  709. X/* allocnode - allocate a new node */
  710. XLOCAL LVAL allocnode(type)
  711. X  int type;
  712. X{
  713. X    LVAL nnode;
  714. X
  715. X    /* get a free node */
  716. X    if ((nnode = fnodes) == NIL) {
  717. X    findmemory();
  718. X    if ((nnode = fnodes) == NIL)
  719. X        xlabort("insufficient node space");
  720. X    }
  721. X
  722. X    /* unlink the node from the free list */
  723. X    fnodes = cdr(nnode);
  724. X    --nfree;
  725. X
  726. X    /* initialize the new node */
  727. X    nnode->n_type = type;
  728. X    rplacd(nnode,NIL);
  729. X
  730. X    /* return the new node */
  731. X    return (nnode);
  732. X}
  733. X
  734. X/* findmemory - garbage collect, then add more node space if necessary */
  735. XLOCAL findmemory()
  736. X{
  737. X    /* first try garbage collecting */
  738. X    gc();
  739. X
  740. X    /* expand memory only if less than one segment is free */
  741. X    if (nfree < (long)NSSIZE)
  742. X    nexpand(1);
  743. X}
  744. X
  745. X/* nexpand - expand node space */
  746. Xnexpand(n)
  747. X  int n;
  748. X{
  749. X    NSEGMENT *newnsegment(),*newseg;
  750. X    LVAL p;
  751. X    int i;
  752. X
  753. X    /* try to add n segments */
  754. X    while (--n >= 0) {
  755. X
  756. X    /* allocate the new segment */
  757. X    if ((newseg = newnsegment(NSSIZE)) == NULL)
  758. X        return;
  759. X
  760. X    /* add each new node to the free list */
  761. X    p = &newseg->ns_data[0];
  762. X    for (i = NSSIZE; --i >= 0; ++p) {
  763. X        p->n_type = FREE;
  764. X        p->n_flags = 0;
  765. X        rplacd(p,fnodes);
  766. X        fnodes = p;
  767. X    }
  768. X    }
  769. X}
  770. X
  771. X/* allocvector - allocate and initialize a new vector node */
  772. XLOCAL LVAL allocvector(type,size)
  773. X  int type,size;
  774. X{
  775. X    register LVAL val,*p;
  776. X    register int i;
  777. X
  778. X    /* get a free node */
  779. X    if ((val = fnodes) == NIL) {
  780. X    findmemory();
  781. X    if ((val = fnodes) == NIL)
  782. X        xlabort("insufficient node space");
  783. X    }
  784. X
  785. X    /* unlink the node from the free list */
  786. X    fnodes = cdr(fnodes);
  787. X    --nfree;
  788. X
  789. X    /* initialize the vector node */
  790. X    val->n_type = type;
  791. X    val->n_vsize = size;
  792. X    val->n_vdata = NULL;
  793. X    cpush(val);
  794. X
  795. X    /* add space for the backpointer */
  796. X    ++size;
  797. X    
  798. X    /* make sure there's enough space */
  799. X    if (!VCOMPARE(vfree,size,vtop)) {
  800. X    findvmemory(size);
  801. X    if (!VCOMPARE(vfree,size,vtop))
  802. X        xlabort("insufficient vector space");
  803. X    }
  804. X
  805. X    /* allocate the next available block */
  806. X    p = vfree;
  807. X    vfree += size;
  808. X    
  809. X    /* store the backpointer */
  810. X    *p++ = top();
  811. X    val->n_vdata = p;
  812. X
  813. X    /* set all the elements to NIL */
  814. X    for (i = size; i > 1; --i)
  815. X    *p++ = NIL;
  816. X
  817. X    /* return the new vector */
  818. X    return (pop());
  819. X}
  820. X
  821. X/* findvmemory - find vector memory */
  822. Xfindvmemory(size)
  823. X  int size;
  824. X{
  825. X    gc();
  826. X    makevmemory(size);
  827. X}
  828. X
  829. X/* makevmemory - make vector memory (used by 'xsimage.c') */
  830. Xmakevmemory(size)
  831. X  int size;
  832. X{
  833. X    VSEGMENT *vseg;
  834. X
  835. X    /* look for a vector segment with enough space */
  836. X    for (vseg = vsegments; vseg != NULL; vseg = vseg->vs_next)
  837. X    if (VCOMPARE(vseg->vs_free,size,vseg->vs_top)) {
  838. X        if (vscurrent != NULL)
  839. X        vscurrent->vs_free = vfree;
  840. X        vfree = vseg->vs_free;
  841. X        vtop = vseg->vs_top;
  842. X        vscurrent = vseg;
  843. X        return;
  844. X    }
  845. X    
  846. X    /* allocate a new vector segment and make it current */
  847. X    vexpand(1);
  848. X}
  849. X
  850. X/* vexpand - expand vector space */
  851. Xvexpand(n)
  852. X  int n;
  853. X{
  854. X    VSEGMENT *newvsegment(),*vseg;
  855. X
  856. X    /* try to add n segments */
  857. X    while (--n >= 0) {
  858. X    if ((vseg = newvsegment(VSSIZE)) == NULL)
  859. X        return;
  860. X    if (vscurrent != NULL)
  861. X        vscurrent->vs_free = vfree;
  862. X    vfree = vseg->vs_free;
  863. X    vtop = vseg->vs_top;
  864. X    vscurrent = vseg;
  865. X    }
  866. X}
  867. X
  868. X/* newnsegment - create a new node segment */
  869. XNSEGMENT *newnsegment(n)
  870. X  unsigned int n;
  871. X{
  872. X    NSEGMENT *newseg;
  873. X
  874. X    /* allocate the new segment */
  875. X    if ((newseg = (NSEGMENT *)calloc(1,nsegsize(n))) == NULL)
  876. X    return (NULL);
  877. X
  878. X    /* initialize the new segment */
  879. X    newseg->ns_size = n;
  880. X    newseg->ns_next = NULL;
  881. X    if (nsegments)
  882. X    nslast->ns_next = newseg;
  883. X    else
  884. X    nsegments = newseg;
  885. X    nslast = newseg;
  886. X
  887. X    /* update the statistics */
  888. X    total += (long)nsegsize(n);
  889. X    nnodes += (long)n;
  890. X    nfree += (long)n;
  891. X    ++nscount;
  892. X
  893. X    /* return the new segment */
  894. X    return (newseg);
  895. X}
  896. X/* newvsegment - create a new vector segment */
  897. XVSEGMENT *newvsegment(n)
  898. X  unsigned int n;
  899. X{
  900. X    VSEGMENT *newseg;
  901. X
  902. X    /* allocate the new segment */
  903. X    if ((newseg = (VSEGMENT *)calloc(1,vsegsize(n))) == NULL)
  904. X    return (NULL);
  905. X
  906. X    /* initialize the new segment */
  907. X    newseg->vs_free = &newseg->vs_data[0];
  908. X    newseg->vs_top = newseg->vs_free + n;
  909. X    newseg->vs_next = vsegments;
  910. X    vsegments = newseg;
  911. X
  912. X    /* update the statistics */
  913. X    total += (long)vsegsize(n);
  914. X    ++vscount;
  915. X
  916. X    /* return the new segment */
  917. X    return (newseg);
  918. X}
  919. X/* gc - garbage collect */
  920. Xgc()
  921. X{
  922. X    register LVAL *p,tmp;
  923. X    int compact();
  924. X
  925. X    /* mark the obarray and the current environment */
  926. X    if (obarray && ispointer(obarray))
  927. X    mark(obarray);
  928. X    if (xlfun && ispointer(xlfun))
  929. X    mark(xlfun);
  930. X    if (xlenv && ispointer(xlenv))
  931. X    mark(xlenv);
  932. X    if (xlval && ispointer(xlval))
  933. X    mark(xlval);
  934. X    if (default_object && ispointer(default_object))
  935. X    mark(default_object);
  936. X    if (eof_object && ispointer(eof_object))
  937. X    mark(eof_object);
  938. X    if (true && ispointer(true))
  939. X    mark(true);
  940. X
  941. X    /* mark the stack */
  942. X    for (p = xlsp; p < xlstktop; ++p)
  943. X    if ((tmp = *p) && ispointer(tmp))
  944. X        mark(tmp);
  945. X
  946. X    /* compact vector space */
  947. X    gc_protect(compact);
  948. X
  949. X    /* sweep memory collecting all unmarked nodes */
  950. X    sweep();
  951. X
  952. X    /* count the gc call */
  953. X    ++gccalls;
  954. X}
  955. X
  956. X/* mark - mark all accessible nodes */
  957. XLOCAL mark(ptr)
  958. X  LVAL ptr;
  959. X{
  960. X    register LVAL this,prev,tmp;
  961. X
  962. X    /* initialize */
  963. X    prev = NIL;
  964. X    this = ptr;
  965. X
  966. X    /* mark this node */
  967. X    for (;;) {
  968. X
  969. X    /* descend as far as we can */
  970. X    while (!(this->n_flags & MARK))
  971. X
  972. X        /* mark this node and trace its children */
  973. X        switch (this->n_type) {
  974. X        case CONS:        /* mark cons-like nodes */
  975. X        case CLOSURE:
  976. X        case METHOD:
  977. X        case PROMISE:
  978. X        case ENV:
  979. X        this->n_flags |= MARK;
  980. X        if ((tmp = car(this)) && ispointer(tmp)) {
  981. X            this->n_flags |= LEFT;
  982. X            rplaca(this,prev);
  983. X            prev = this;
  984. X            this = tmp;
  985. X        }
  986. X        else if ((tmp = cdr(this)) && ispointer(tmp)) {
  987. X            rplacd(this,prev);
  988. X            prev = this;
  989. X            this = tmp;
  990. X        }
  991. X        break;
  992. X        case SYMBOL:    /* mark vector-like nodes */
  993. X        case OBJECT:
  994. X        case VECTOR:
  995. X        case CODE:
  996. X        case CONTINUATION:
  997. X        this->n_flags |= MARK;
  998. X        markvector(this);
  999. X        break;
  1000. X        default:        /* mark all other types of nodes */
  1001. X        this->n_flags |= MARK;
  1002. X        break;
  1003. X        }
  1004. X
  1005. X    /* backup to a point where we can continue descending */
  1006. X    for (;;)
  1007. X
  1008. X        /* make sure there is a previous node */
  1009. X        if (prev) {
  1010. X        if (prev->n_flags & LEFT) {    /* came from left side */
  1011. X            prev->n_flags &= ~LEFT;
  1012. X            tmp = car(prev);
  1013. X            rplaca(prev,this);
  1014. X            if ((this = cdr(prev)) && ispointer(this)) {
  1015. X            rplacd(prev,tmp);            
  1016. X            break;
  1017. X            }
  1018. X        }
  1019. X        else {                /* came from right side */
  1020. X            tmp = cdr(prev);
  1021. X            rplacd(prev,this);
  1022. X        }
  1023. X        this = prev;            /* step back up the branch */
  1024. X        prev = tmp;
  1025. X        }
  1026. X
  1027. X        /* no previous node, must be done */
  1028. X        else
  1029. X        return;
  1030. X    }
  1031. X}
  1032. X
  1033. X/* markvector - mark a vector-like node */
  1034. XLOCAL markvector(vect)
  1035. X  LVAL vect;
  1036. X{
  1037. X    register LVAL tmp,*p;
  1038. X    register int n;
  1039. X    if (p = vect->n_vdata) {
  1040. X    n = getsize(vect);
  1041. X    while (--n >= 0)
  1042. X        if ((tmp = *p++) != NULL && ispointer(tmp))
  1043. X        mark(tmp);
  1044. X    }
  1045. X}
  1046. X
  1047. X/* compact - compact vector space */
  1048. XLOCAL compact()
  1049. X{
  1050. X    VSEGMENT *vseg;
  1051. X
  1052. X    /* store the current segment information */
  1053. X    if (vscurrent)
  1054. X    vscurrent->vs_free = vfree;
  1055. X
  1056. X    /* compact each vector segment */
  1057. X    for (vseg = vsegments; vseg != NULL; vseg = vseg->vs_next)
  1058. X    compact_vector(vseg);
  1059. X
  1060. X    /* make the first vector segment current */
  1061. X    if (vscurrent = vsegments) {
  1062. X    vfree = vscurrent->vs_free;
  1063. X    vtop = vscurrent->vs_top;
  1064. X    }
  1065. X}
  1066. X
  1067. X/* compact_vector - compact a vector segment */
  1068. XLOCAL compact_vector(vseg)
  1069. X  VSEGMENT *vseg;
  1070. X{
  1071. X    register LVAL *vdata,*vnext,*vfree,vector;
  1072. X    register int vsize;
  1073. X
  1074. X    vdata = vnext = &vseg->vs_data[0];
  1075. X    vfree = vseg->vs_free;
  1076. X    while (vdata < vfree) {
  1077. X    vector = *vdata;
  1078. X    if (vector->n_type == STRING)
  1079. X        vsize = btow_size(vector->n_vsize) + 1;
  1080. X    else
  1081. X        vsize = vector->n_vsize + 1;
  1082. X    if (vector->n_flags & MARK) {
  1083. X        if (vdata == vnext) {
  1084. X        vdata += vsize;
  1085. X        vnext += vsize;
  1086. X        }
  1087. X        else {
  1088. X        vector->n_vdata = vnext + 1;
  1089. X        while (vsize > 0) {
  1090. X            *vnext++ = *vdata++;
  1091. X            --vsize;
  1092. X        }
  1093. X        }
  1094. X    }
  1095. X    else
  1096. X        vdata += vsize;
  1097. X    }
  1098. X    vseg->vs_free = vnext;
  1099. X}
  1100. X
  1101. X/* sweep - sweep all unmarked nodes and add them to the free list */
  1102. XLOCAL sweep()
  1103. X{
  1104. X    NSEGMENT *nseg;
  1105. X
  1106. X    /* empty the free list */
  1107. X    fnodes = NIL;
  1108. X    nfree = 0L;
  1109. X
  1110. X    /* sweep each node segment */
  1111. X    for (nseg = nsegments; nseg != NULL; nseg = nseg->ns_next)
  1112. X    sweep_segment(nseg);
  1113. X}
  1114. X
  1115. X/* sweep_segment - sweep a node segment */
  1116. XLOCAL sweep_segment(nseg)
  1117. X  NSEGMENT *nseg;
  1118. X{
  1119. X    register FIXTYPE n;
  1120. X    register LVAL p;
  1121. X
  1122. X    /* add all unmarked nodes */
  1123. X    for (p = &nseg->ns_data[0], n = nseg->ns_size; --n >= 0L; ++p)
  1124. X    if (!(p->n_flags & MARK)) {
  1125. X        switch (p->n_type) {
  1126. X        case PORT:
  1127. X        if (getfile(p))
  1128. X            osclose(getfile(p));
  1129. X        break;
  1130. X        }
  1131. X        p->n_type = FREE;
  1132. X        rplacd(p,fnodes);
  1133. X        fnodes = p;
  1134. X        ++nfree;
  1135. X    }
  1136. X    else
  1137. X        p->n_flags &= ~MARK;
  1138. X}
  1139. X
  1140. X/* xlminit - initialize the dynamic memory module */
  1141. Xxlminit(ssize)
  1142. X  unsigned int ssize;
  1143. X{
  1144. X    unsigned int n;
  1145. X    
  1146. X    /* initialize our internal variables */
  1147. X    gccalls = 0;
  1148. X    total = 0L;
  1149. X
  1150. X    /* initialize node space */
  1151. X    nsegments = nslast = NULL;
  1152. X    nscount = 0;
  1153. X    nnodes = nfree = 0L;
  1154. X    fnodes = NIL;
  1155. X
  1156. X    /* initialize vector space */
  1157. X    vsegments = vscurrent = NULL;
  1158. X    vscount = 0;
  1159. X    vfree = vtop = NULL;
  1160. X    
  1161. X    /* allocate the value stack */
  1162. X    n = ssize * sizeof(LVAL);
  1163. X    if ((xlstkbase = (LVAL *)calloc(1,n)) == NULL)
  1164. X    xlfatal("insufficient memory");
  1165. X    total += (long)n;
  1166. X
  1167. X    /* initialize structures that are marked by the collector */
  1168. X    obarray = default_object = eof_object = true = NIL;
  1169. X    xlfun = xlenv = xlval = NIL;
  1170. X
  1171. X    /* initialize the stack */
  1172. X    xlsp = xlstktop = xlstkbase + ssize;
  1173. X}
  1174. END_OF_FILE
  1175. if test 15137 -ne `wc -c <'Src/xsdmem.c'`; then
  1176.     echo shar: \"'Src/xsdmem.c'\" unpacked with wrong size!
  1177. fi
  1178. # end of 'Src/xsdmem.c'
  1179. fi
  1180. if test -f 'Src/xsftab.c' -a "${1}" != "-c" ; then 
  1181.   echo shar: Will not clobber existing file \"'Src/xsftab.c'\"
  1182. else
  1183. echo shar: Extracting \"'Src/xsftab.c'\" \(14063 characters\)
  1184. sed "s/^X//" >'Src/xsftab.c' <<'END_OF_FILE'
  1185. X/* xsftab.c - built-in function table */
  1186. X/*    Copyright (c) 1988, by David Michael Betz
  1187. X    All Rights Reserved
  1188. X    Permission is granted for unrestricted non-commercial use    */
  1189. X
  1190. X#include "xscheme.h"
  1191. X
  1192. X/* external variables */
  1193. Xextern LVAL s_stdin,s_stdout;
  1194. X
  1195. X/* external functions */
  1196. Xextern LVAL
  1197. X    xapply(),xcallcc(),xmap(),xmap1(),xforeach(),xforeach1(),
  1198. X    xforce(),xforce1(),xcallwi(),xcallwo(),xwithfile1(),
  1199. X    xload(),xloadnoisily(),xload1(),
  1200. X    xsendsuper(),clnew(),clisnew(),clanswer(),
  1201. X    obisnew(),obclass(),obshow(),
  1202. X    xcons(),xcar(),xcdr(),
  1203. X    xcaar(),xcadr(),xcdar(),xcddr(),
  1204. X    xcaaar(),xcaadr(),xcadar(),xcaddr(),
  1205. X    xcdaar(),xcdadr(),xcddar(),xcdddr(),
  1206. X    xcaaaar(),xcaaadr(),xcaadar(),xcaaddr(),
  1207. X    xcadaar(),xcadadr(),xcaddar(),xcadddr(),
  1208. X    xcdaaar(),xcdaadr(),xcdadar(),xcdaddr(),
  1209. X    xcddaar(),xcddadr(),xcdddar(),xcddddr(),
  1210. X    xsetcar(),xsetcdr(),xlist(),
  1211. X    xappend(),xreverse(),xlastpair(),xlength(),xlistref(),xlisttail(),
  1212. X    xmember(),xmemv(),xmemq(),xassoc(),xassv(),xassq(),
  1213. X    xsymvalue(),xsetsymvalue(),xsymplist(),xsetsymplist(),xgensym(),
  1214. X    xboundp(),xget(),xput(),
  1215. X    xtheenvironment(),xprocenvironment(),xenvp(),xenvbindings(),xenvparent(),
  1216. X    xvector(),xmakevector(),xvlength(),xvref(),xvset(),
  1217. X    xvectlist(),xlistvect(),
  1218. X    xmakearray(),xaref(),xaset(),
  1219. X    xsymstr(),xstrsym(),
  1220. X    xnull(),xatom(),xlistp(),xnumberp(),xbooleanp(),
  1221. X    xpairp(),xsymbolp(),xintegerp(),xrealp(),xcharp(),xstringp(),xvectorp(),
  1222. X    xprocedurep(),xobjectp(),xdefaultobjectp(),
  1223. X    xinputportp(),xoutputportp(),xportp(),
  1224. X    xeq(),xeqv(),xequal(),
  1225. X    xzerop(),xpositivep(),xnegativep(),xoddp(),xevenp(),
  1226. X    xexactp(),xinexactp(),
  1227. X    xadd1(),xsub1(),xabs(),xgcd(),xrandom(),
  1228. X    xadd(),xsub(),xmul(),xdiv(),xquo(),xrem(),xmin(),xmax(),
  1229. X    xsin(),xcos(),xtan(),xasin(),xacos(),xatan(),
  1230. X    xxexp(),xsqrt(),xexpt(),xxlog(),xtruncate(),xfloor(),xceiling(),xround(),
  1231. X    xlogand(),xlogior(),xlogxor(),xlognot(),
  1232. X    xlss(),xleq(),xeql(),xgeq(),xgtr(),
  1233. X    xstrlen(),xstrnullp(),xstrappend(),xstrref(),xsubstring(),
  1234. X    xstrlist(),xliststring(),
  1235. X    xstrlss(),xstrleq(),xstreql(),xstrgeq(),xstrgtr(),
  1236. X    xstrilss(),xstrileq(),xstrieql(),xstrigeq(),xstrigtr(),
  1237. X    xcharint(),xintchar(),
  1238. X    xchrlss(),xchrleq(),xchreql(),xchrgeq(),xchrgtr(),
  1239. X    xchrilss(),xchrileq(),xchrieql(),xchrigeq(),xchrigtr(),
  1240. X    xread(),xrdchar(),xrdbyte(),xrdshort(),xrdlong(),xeofobjectp(),
  1241. X    xwrite(),xwrchar(),xwrbyte(),xwrshort(),xwrlong(),
  1242. X    xdisplay(),xnewline(),xprint(),xprbreadth(),xprdepth(),
  1243. X    xopeni(),xopeno(),xopena(),xopenu(),xclosei(),xcloseo(),xclose(),
  1244. X    xgetfposition(),xsetfposition(),xcurinput(),xcuroutput(),
  1245. X    xtranson(),xtransoff(),xgetarg(),xexit(),xcompile(),xdecompile(),xgc(),
  1246. X    xsave(),xrestore(),xtraceon(),xtraceoff(),xreset(),xerror(),
  1247. X    xicar(),xicdr(),xisetcar(),xisetcdr(),xivlength(),xivref(),xivset();
  1248. X#ifdef MACINTOSH
  1249. Xextern LVAL xhidepen(),xshowpen(),xgetpen(),xpensize(),xpenmode();
  1250. Xextern LVAL xpenpat(),xpennormal(),xmoveto(),xmove(),xlineto(),xline();
  1251. Xextern LVAL xshowgraphics(),xhidegraphics(),xcleargraphics();
  1252. X#endif
  1253. X#ifdef MSDOS
  1254. Xextern LVAL xint86(),xinbyte(),xoutbyte(),xsystem(),xgetkey();
  1255. X#endif
  1256. X#ifdef UNIX
  1257. Xextern LVAL xsystem();
  1258. X#endif
  1259. X#ifdef AZTEC_AMIGA
  1260. Xextern LVAL xsystem();
  1261. X#endif
  1262. X
  1263. Xint xsubrcnt = 12;    /* number of XSUBR functions */
  1264. Xint csubrcnt = 17;    /* number of CSUBR functions + xsubrcnt */
  1265. X
  1266. X/* built-in functions */
  1267. XFUNDEF funtab[] = {
  1268. X
  1269. X    /* functions that call eval or apply (# must match xsubrcnt) */
  1270. X{    "APPLY",                xapply        },
  1271. X{    "CALL-WITH-CURRENT-CONTINUATION",    xcallcc        },
  1272. X{    "CALL/CC",                xcallcc        },
  1273. X{    "MAP",                    xmap        },
  1274. X{    "FOR-EACH",                xforeach    },
  1275. X{    "CALL-WITH-INPUT-FILE",            xcallwi        },
  1276. X{    "CALL-WITH-OUTPUT-FILE",        xcallwo        },
  1277. X{    "LOAD",                    xload        },
  1278. X{    "LOAD-NOISILY",                xloadnoisily    },
  1279. X{    "SEND-SUPER",                xsendsuper    },
  1280. X{    "%CLASS-NEW",                clnew        },
  1281. X{    "FORCE",                xforce        },
  1282. X
  1283. X    /* continuations for xsubrs (# must match csubrcnt) */
  1284. X{    "%MAP1",                xmap1        },
  1285. X{    "%FOR-EACH1",                xforeach1    },
  1286. X{    "%WITH-FILE1",                xwithfile1    },
  1287. X{    "%LOAD1",                xload1        },
  1288. X{    "%FORCE1",                xforce1        },
  1289. X
  1290. X    /* methods */
  1291. X{    "%CLASS-ISNEW",                clisnew        },
  1292. X{    "%CLASS-ANSWER",            clanswer    },
  1293. X{    "%OBJECT-ISNEW",            obisnew        },
  1294. X{    "%OBJECT-CLASS",            obclass        },
  1295. X{    "%OBJECT-SHOW",                obshow        },
  1296. X
  1297. X    /* list functions */
  1298. X{    "CONS",                    xcons        },
  1299. X{    "CAR",                    xcar        },
  1300. X{    "CDR",                    xcdr        },
  1301. X{    "CAAR",                    xcaar        },
  1302. X{    "CADR",                    xcadr        },
  1303. X{    "CDAR",                    xcdar        },
  1304. X{    "CDDR",                    xcddr        },
  1305. X{    "CAAAR",                xcaaar        },
  1306. X{    "CAADR",                xcaadr        },
  1307. X{    "CADAR",                xcadar        },
  1308. X{    "CADDR",                xcaddr        },
  1309. X{    "CDAAR",                xcdaar        },
  1310. X{    "CDADR",                xcdadr        },
  1311. X{    "CDDAR",                xcddar        },
  1312. X{    "CDDDR",                xcdddr        },
  1313. X{    "CAAAAR",                 xcaaaar        },
  1314. X{    "CAAADR",                xcaaadr        },
  1315. X{    "CAADAR",                xcaadar        },
  1316. X{    "CAADDR",                xcaaddr        },
  1317. X{    "CADAAR",                 xcadaar        },
  1318. X{    "CADADR",                xcadadr        },
  1319. X{    "CADDAR",                xcaddar        },
  1320. X{    "CADDDR",                xcadddr        },
  1321. X{    "CDAAAR",                xcdaaar        },
  1322. X{    "CDAADR",                xcdaadr        },
  1323. X{    "CDADAR",                xcdadar        },
  1324. X{    "CDADDR",                xcdaddr        },
  1325. X{    "CDDAAR",                xcddaar        },
  1326. X{    "CDDADR",                xcddadr        },
  1327. X{    "CDDDAR",                xcdddar        },
  1328. X{    "CDDDDR",                xcddddr        },
  1329. X{    "LIST",                    xlist        },
  1330. X{    "APPEND",                xappend        },
  1331. X{    "REVERSE",                xreverse    },
  1332. X{    "LAST-PAIR",                xlastpair    },
  1333. X{    "LENGTH",                xlength        },
  1334. X{    "MEMBER",                xmember        },
  1335. X{    "MEMV",                    xmemv        },
  1336. X{    "MEMQ",                    xmemq        },
  1337. X{    "ASSOC",                xassoc        },
  1338. X{    "ASSV",                    xassv        },
  1339. X{    "ASSQ",                    xassq        },
  1340. X{    "LIST-REF",                xlistref    },
  1341. X{    "LIST-TAIL",                xlisttail    },
  1342. X
  1343. X    /* destructive list functions */
  1344. X{    "SET-CAR!",                xsetcar        },
  1345. X{    "SET-CDR!",                xsetcdr        },
  1346. X
  1347. X
  1348. X    /* symbol functions */
  1349. X{    "BOUND?",                xboundp        },
  1350. X{    "SYMBOL-VALUE",                xsymvalue    },
  1351. X{    "SET-SYMBOL-VALUE!",            xsetsymvalue    },
  1352. X{    "SYMBOL-PLIST",                xsymplist    },
  1353. X{    "SET-SYMBOL-PLIST!",            xsetsymplist    },
  1354. X{    "GENSYM",                xgensym        },
  1355. X{    "GET",                    xget        },
  1356. X{    "PUT",                    xput        },
  1357. X
  1358. X    /* environment functions */
  1359. X{    "THE-ENVIRONMENT",            xtheenvironment    },
  1360. X{    "PROCEDURE-ENVIRONMENT",        xprocenvironment},
  1361. X{    "ENVIRONMENT?",                xenvp        },
  1362. X{    "ENVIRONMENT-BINDINGS",            xenvbindings    },
  1363. X{    "ENVIRONMENT-PARENT",            xenvparent    },
  1364. X
  1365. X    /* vector functions */
  1366. X{    "VECTOR",                xvector        },
  1367. X{    "MAKE-VECTOR",                xmakevector    },
  1368. X{    "VECTOR-LENGTH",            xvlength    },
  1369. X{    "VECTOR-REF",                xvref        },
  1370. X{    "VECTOR-SET!",                xvset        },
  1371. X
  1372. X    /* array functions */
  1373. X{    "MAKE-ARRAY",                xmakearray    },
  1374. X{    "ARRAY-REF",                xaref        },
  1375. X{    "ARRAY-SET!",                xaset        },
  1376. X
  1377. X    /* conversion functions */
  1378. X{    "SYMBOL->STRING",            xsymstr        },
  1379. X{    "STRING->SYMBOL",            xstrsym        },
  1380. X{    "VECTOR->LIST",                xvectlist    },
  1381. X{    "LIST->VECTOR",                xlistvect    },
  1382. X{    "STRING->LIST",                xstrlist    },
  1383. X{    "LIST->STRING",                xliststring    },
  1384. X{    "CHAR->INTEGER",            xcharint    },
  1385. X{    "INTEGER->CHAR",            xintchar    },
  1386. X
  1387. X    /* predicate functions */
  1388. X{    "NULL?",                xnull        },
  1389. X{    "ATOM?",                xatom        },
  1390. X{    "LIST?",                xlistp        },
  1391. X{    "NUMBER?",                xnumberp    },
  1392. X{    "BOOLEAN?",                xbooleanp    },
  1393. X{    "PAIR?",                xpairp        },
  1394. X{    "SYMBOL?",                xsymbolp    },
  1395. X{    "COMPLEX?",                xrealp        }, /*(1)*/
  1396. X{    "REAL?",                xrealp        },
  1397. X{    "RATIONAL?",                xintegerp    }, /*(1)*/
  1398. X{    "INTEGER?",                xintegerp    },
  1399. X{    "CHAR?",                xcharp        },
  1400. X{    "STRING?",                xstringp    },
  1401. X{    "VECTOR?",                xvectorp    },
  1402. X{    "PROCEDURE?",                xprocedurep    },
  1403. X{    "PORT?",                xportp        },
  1404. X{    "INPUT-PORT?",                xinputportp    },
  1405. X{    "OUTPUT-PORT?",                xoutputportp    },
  1406. X{    "OBJECT?",                xobjectp    },
  1407. X{    "EOF-OBJECT?",                xeofobjectp    },
  1408. X{    "DEFAULT-OBJECT?",            xdefaultobjectp    },
  1409. X{    "EQ?",                    xeq        },
  1410. X{    "EQV?",                    xeqv        },
  1411. X{    "EQUAL?",                xequal        },
  1412. X
  1413. X    /* arithmetic functions */
  1414. X{    "ZERO?",                xzerop        },
  1415. X{    "POSITIVE?",                xpositivep    },
  1416. X{    "NEGATIVE?",                xnegativep    },
  1417. X{    "ODD?",                    xoddp        },
  1418. X{    "EVEN?",                xevenp        },
  1419. X{    "EXACT?",                xexactp        },
  1420. X{    "INEXACT?",                xinexactp    },
  1421. X{    "TRUNCATE",                xtruncate    },
  1422. X{    "FLOOR",                xfloor        },
  1423. X{    "CEILING",                xceiling    },
  1424. X{    "ROUND",                xround        },
  1425. X{    "1+",                    xadd1        },
  1426. X{    "-1+",                    xsub1        },
  1427. X{    "ABS",                    xabs        },
  1428. X{    "GCD",                    xgcd        },
  1429. X{    "RANDOM",                xrandom        },
  1430. X{    "+",                    xadd        },
  1431. X{    "-",                    xsub        },
  1432. X{    "*",                    xmul        },
  1433. X{    "/",                    xdiv        },
  1434. X{    "QUOTIENT",                xquo        },
  1435. X{    "REMAINDER",                xrem        },
  1436. X{    "MIN",                    xmin        },
  1437. X{    "MAX",                    xmax        },
  1438. X{    "SIN",                    xsin        },
  1439. X{    "COS",                    xcos        },
  1440. X{    "TAN",                    xtan        },
  1441. X{    "ASIN",                    xasin        },
  1442. X{    "ACOS",                    xacos        },
  1443. X{    "ATAN",                    xatan        },
  1444. X{    "EXP",                    xxexp        },
  1445. X{    "SQRT",                    xsqrt        },
  1446. X{    "EXPT",                    xexpt        },
  1447. X{    "LOG",                    xxlog        },
  1448. X
  1449. X    /* bitwise logical functions */
  1450. X{    "LOGAND",                xlogand        },
  1451. X{    "LOGIOR",                xlogior        },
  1452. X{    "LOGXOR",                xlogxor        },
  1453. X{    "LOGNOT",                xlognot        },
  1454. X
  1455. X    /* numeric comparison functions */
  1456. X{    "<",                    xlss        },
  1457. X{    "<=",                    xleq        },
  1458. X{    "=",                    xeql        },
  1459. X{    ">=",                    xgeq        },
  1460. X{    ">",                    xgtr        },
  1461. X
  1462. X    /* string functions */
  1463. X{    "STRING-LENGTH",            xstrlen        },
  1464. X{    "STRING-NULL?",                xstrnullp    },
  1465. X{    "STRING-APPEND",            xstrappend    },
  1466. X{    "STRING-REF",                xstrref        },
  1467. X{    "SUBSTRING",                xsubstring    },
  1468. X{    "STRING<?",                xstrlss        },
  1469. X{    "STRING<=?",                xstrleq        },
  1470. X{    "STRING=?",                xstreql        },
  1471. X{    "STRING>=?",                xstrgeq        },
  1472. X{    "STRING>?",                xstrgtr        },
  1473. X{    "STRING-CI<?",                xstrilss    },
  1474. X{    "STRING-CI<=?",                xstrileq    },
  1475. X{    "STRING-CI=?",                xstrieql    },
  1476. X{    "STRING-CI>=?",                xstrigeq    },
  1477. X{    "STRING-CI>?",                xstrigtr    },
  1478. X
  1479. X    /* character functions */
  1480. X{    "CHAR<?",                xchrlss        },
  1481. X{    "CHAR<=?",                xchrleq        },
  1482. X{    "CHAR=?",                xchreql        },
  1483. X{    "CHAR>=?",                xchrgeq        },
  1484. X{    "CHAR>?",                xchrgtr        },
  1485. X{    "CHAR-CI<?",                xchrilss    },
  1486. X{    "CHAR-CI<=?",                xchrileq    },
  1487. X{    "CHAR-CI=?",                xchrieql    },
  1488. X{    "CHAR-CI>=?",                xchrigeq    },
  1489. X{    "CHAR-CI>?",                xchrigtr    },
  1490. X
  1491. X    /* I/O functions */
  1492. X{    "READ",                    xread        },
  1493. X{    "READ-CHAR",                xrdchar        },
  1494. X{    "READ-BYTE",                xrdbyte        },
  1495. X{    "READ-SHORT",                xrdshort    },
  1496. X{    "READ-LONG",                xrdlong        },
  1497. X{    "WRITE",                xwrite        },
  1498. X{    "WRITE-CHAR",                xwrchar        },
  1499. X{    "WRITE-BYTE",                xwrbyte        },
  1500. X{    "WRITE-SHORT",                xwrshort    },
  1501. X{    "WRITE-LONG",                xwrlong        },
  1502. X{    "DISPLAY",                xdisplay    },
  1503. X{    "PRINT",                xprint        },
  1504. X{    "NEWLINE",                xnewline    },
  1505. X
  1506. X    /* print control functions */
  1507. X{    "PRINT-BREADTH",            xprbreadth    },
  1508. X{    "PRINT-DEPTH",                xprdepth    },
  1509. X
  1510. X    /* file I/O functions */
  1511. X{    "OPEN-INPUT-FILE",            xopeni        },
  1512. X{    "OPEN-OUTPUT-FILE",            xopeno        },
  1513. X{    "OPEN-APPEND-FILE",            xopena        },
  1514. X{    "OPEN-UPDATE-FILE",            xopenu        },
  1515. X{    "CLOSE-PORT",                xclose        },
  1516. X{    "CLOSE-INPUT-PORT",            xclosei        },
  1517. X{    "CLOSE-OUTPUT-PORT",            xcloseo        },
  1518. X{    "GET-FILE-POSITION",            xgetfposition    },
  1519. X{    "SET-FILE-POSITION!",            xsetfposition    },
  1520. X{    "CURRENT-INPUT-PORT",            xcurinput    },
  1521. X{    "CURRENT-OUTPUT-PORT",            xcuroutput    },
  1522. X
  1523. X    /* utility functions */
  1524. X{    "TRANSCRIPT-ON",            xtranson    },
  1525. X{    "TRANSCRIPT-OFF",            xtransoff    },
  1526. X{    "GETARG",                xgetarg        },
  1527. X{    "EXIT",                    xexit        },
  1528. X{    "COMPILE",                xcompile    },
  1529. X{    "DECOMPILE",                xdecompile    },
  1530. X{    "GC",                    xgc        },
  1531. X{    "SAVE",                    xsave        },
  1532. X{    "RESTORE",                xrestore    },
  1533. X{    "RESET",                xreset        },
  1534. X{    "ERROR",                xerror        },
  1535. X
  1536. X    /* debugging functions */
  1537. X{    "TRACE-ON",                xtraceon    },
  1538. X{    "TRACE-OFF",                xtraceoff    },
  1539. X
  1540. X    /* internal functions */
  1541. X{    "%CAR",                    xicar        },
  1542. X{    "%CDR",                    xicdr        },
  1543. X{    "%SET-CAR!",                xisetcar    },
  1544. X{    "%SET-CDR!",                xisetcdr    },
  1545. X{    "%VECTOR-LENGTH",            xivlength    },
  1546. X{    "%VECTOR-REF",                xivref        },
  1547. X{    "%VECTOR-SET!",                xivset        },
  1548. X
  1549. X#ifdef MACINTOSH
  1550. X{    "HIDEPEN",                xhidepen    },
  1551. X{    "SHOWPEN",                xshowpen    },
  1552. X{    "GETPEN",                xgetpen        },
  1553. X{    "PENSIZE",                xpensize    },
  1554. X{    "PENMODE",                xpenmode    },
  1555. X{    "PENPAT",                xpenpat        },
  1556. X{    "PENNORMAL",                xpennormal    },
  1557. X{    "MOVETO",                xmoveto        },
  1558. X{    "MOVE",                    xmove        },
  1559. X{    "LINETO",                xlineto        },
  1560. X{    "LINE",                    xline        },
  1561. X{    "SHOW-GRAPHICS",            xshowgraphics    },
  1562. X{    "HIDE-GRAPHICS",            xhidegraphics    },
  1563. X{    "CLEAR-GRAPHICS",            xcleargraphics    },
  1564. X#endif
  1565. X
  1566. X#ifdef MSDOS
  1567. X{    "INT86",                xint86        },
  1568. X{    "INBYTE",                xinbyte        },
  1569. X{    "OUTBYTE",                xoutbyte    },
  1570. X{    "SYSTEM",                xsystem        },
  1571. X{    "GET-KEY",                xgetkey        },
  1572. X#endif
  1573. X
  1574. X#ifdef UNIX
  1575. X{    "SYSTEM",                xsystem        },
  1576. X#endif
  1577. X
  1578. X#ifdef AZTEC_AMIGA
  1579. X{    "SYSTEM",                xsystem        },
  1580. X#endif
  1581. X
  1582. X{0,0} /* end of table marker */
  1583. X
  1584. X};
  1585. X
  1586. X/* Notes:
  1587. X
  1588. X   (1)    This version only supports integers and reals.
  1589. X
  1590. X*/
  1591. X
  1592. X/* curinput - get the current input port */
  1593. XLVAL curinput()
  1594. X{
  1595. X    return (getvalue(s_stdin));
  1596. X}
  1597. X
  1598. X/* curoutput - get the current output port */
  1599. XLVAL curoutput()
  1600. X{
  1601. X    return (getvalue(s_stdout));
  1602. X}
  1603. X
  1604. X/* eq - internal 'eq?' function */
  1605. Xint eq(arg1,arg2)
  1606. X  LVAL arg1,arg2;
  1607. X{
  1608. X    return (arg1 == arg2);
  1609. X}
  1610. X
  1611. X/* eqv - internal 'eqv?' function */
  1612. Xint eqv(arg1,arg2)
  1613. X  LVAL arg1,arg2;
  1614. X{
  1615. X    /* try the eq test first */
  1616. X    if (arg1 == arg2)
  1617. X    return (TRUE);
  1618. X
  1619. X    /* compare fixnums, flonums and characters */
  1620. X    if (!null(arg1)) {
  1621. X    switch (ntype(arg1)) {
  1622. X    case FIXNUM:
  1623. X        return (fixp(arg2)
  1624. X             && getfixnum(arg1) == getfixnum(arg2));
  1625. X    case FLONUM:
  1626. X        return (floatp(arg2)
  1627. X             && getflonum(arg1) == getflonum(arg2));
  1628. X    case CHAR:
  1629. X        return (charp(arg2)
  1630. X             && getchcode(arg1) == getchcode(arg2));
  1631. X    }
  1632. X    }
  1633. X    return (FALSE);
  1634. X}
  1635. X
  1636. X/* equal - internal 'equal?' function */
  1637. Xint equal(arg1,arg2)
  1638. X  LVAL arg1,arg2;
  1639. X{
  1640. X    /* try the eq test first */
  1641. X    if (arg1 == arg2)
  1642. X    return (TRUE);
  1643. X
  1644. X    /* compare fixnums, flonums, characters, strings, vectors and conses */
  1645. X    if (!null(arg1)) {
  1646. X    switch (ntype(arg1)) {
  1647. X    case FIXNUM:
  1648. X        return (fixp(arg2)
  1649. X             && getfixnum(arg1) == getfixnum(arg2));
  1650. X    case FLONUM:
  1651. X        return (floatp(arg2)
  1652. X             && getflonum(arg1) == getflonum(arg2));
  1653. X    case CHAR:
  1654. X        return (charp(arg2)
  1655. X             && getchcode(arg1) == getchcode(arg2));
  1656. X    case STRING:
  1657. X        return (stringp(arg2)
  1658. X             && strcmp(getstring(arg1),getstring(arg2)) == 0);
  1659. X    case VECTOR:
  1660. X        return (vectorp(arg2)
  1661. X             && vectorequal(arg1,arg2));
  1662. X    case CONS:
  1663. X        return (consp(arg2)
  1664. X             && equal(car(arg1),car(arg2))
  1665. X             && equal(cdr(arg1),cdr(arg2)));
  1666. X    }
  1667. X    }
  1668. X    return (FALSE);
  1669. X}
  1670. X
  1671. X/* vectorequal - compare two vectors */
  1672. Xint vectorequal(v1,v2)
  1673. X  LVAL v1,v2;
  1674. X{
  1675. X    int len,i;
  1676. X
  1677. X    /* compare the vector lengths */
  1678. X    if ((len = getsize(v1)) != getsize(v2))
  1679. X    return (FALSE);
  1680. X
  1681. X    /* compare the vector elements */
  1682. X    for (i = 0; i < len; ++i)
  1683. X    if (!equal(getelement(v1,i),getelement(v2,i)))
  1684. X        return (FALSE);
  1685. X    return (TRUE);
  1686. X}
  1687. X
  1688. X/* xltoofew - too few arguments to this function */
  1689. XLVAL xltoofew()
  1690. X{
  1691. X    xlfail("too few arguments");
  1692. X}
  1693. X
  1694. X/* xltoomany - too many arguments to this function */
  1695. Xxltoomany()
  1696. X{
  1697. X    xlfail("too many arguments");
  1698. X}
  1699. X
  1700. X/* xlbadtype - incorrect argument type */
  1701. XLVAL xlbadtype(val)
  1702. X  LVAL val;
  1703. X{
  1704. X    xlerror("incorrect type",val);
  1705. X}
  1706. END_OF_FILE
  1707. if test 14063 -ne `wc -c <'Src/xsftab.c'`; then
  1708.     echo shar: \"'Src/xsftab.c'\" unpacked with wrong size!
  1709. fi
  1710. # end of 'Src/xsftab.c'
  1711. fi
  1712. if test -f 'Src/xsmath.c' -a "${1}" != "-c" ; then 
  1713.   echo shar: Will not clobber existing file \"'Src/xsmath.c'\"
  1714. else
  1715. echo shar: Extracting \"'Src/xsmath.c'\" \(13437 characters\)
  1716. sed "s/^X//" >'Src/xsmath.c' <<'END_OF_FILE'
  1717. X/* xsmath.c - xscheme built-in arithmetic functions */
  1718. X/*    Copyright (c) 1988, by David Michael Betz
  1719. X    All Rights Reserved
  1720. X    Permission is granted for unrestricted non-commercial use    */
  1721. X
  1722. X#include "xscheme.h"
  1723. X#include <math.h>
  1724. X
  1725. X/* external variables */
  1726. Xextern LVAL true;
  1727. X
  1728. X/* forward declarations */
  1729. XFORWARD LVAL unary();
  1730. XFORWARD LVAL binary();
  1731. XFORWARD LVAL predicate();
  1732. XFORWARD LVAL compare();
  1733. XFORWARD FLOTYPE toflotype();
  1734. X
  1735. X/* xexactp - built-in function 'exact?' */
  1736. X/**** THIS IS REALLY JUST A STUB FOR NOW ****/
  1737. XLVAL xexactp()
  1738. X{
  1739. X    LVAL arg;
  1740. X    arg = xlganumber();
  1741. X    xllastarg();
  1742. X    return (NIL);
  1743. X}
  1744. X
  1745. X/* xinexactp - built-in function 'inexact?' */
  1746. X/**** THIS IS REALLY JUST A STUB FOR NOW ****/
  1747. XLVAL xinexactp()
  1748. X{
  1749. X    LVAL arg;
  1750. X    arg = xlganumber();
  1751. X    xllastarg();
  1752. X    return (true);
  1753. X}
  1754. X
  1755. X/* xatan - built-in function 'atan' */
  1756. XLVAL xatan()
  1757. X{
  1758. X    LVAL arg,arg2;
  1759. X    FLOTYPE val;
  1760. X    
  1761. X    /* get the first argument */
  1762. X    arg = xlganumber();
  1763. X    
  1764. X    /* handle two argument (atan y x) */
  1765. X    if (moreargs()) {
  1766. X    arg2 = xlganumber();
  1767. X    xllastarg();
  1768. X    val = atan2(toflotype(arg),toflotype(arg2));
  1769. X    }
  1770. X    
  1771. X    /* handle one argument (atan x) */
  1772. X    else
  1773. X    val = atan(toflotype(arg));
  1774. X
  1775. X    /* return the resulting flonum */
  1776. X    return (cvflonum(val));
  1777. X}
  1778. X
  1779. X/* xfloor - built-in function 'floor' */
  1780. XLVAL xfloor()
  1781. X{
  1782. X    LVAL arg;
  1783. X
  1784. X    /* get the argument */
  1785. X    arg = xlgetarg();
  1786. X    xllastarg();
  1787. X
  1788. X    /* check its type */
  1789. X    if (fixp(arg))
  1790. X    return (arg);
  1791. X    else if (floatp(arg))
  1792. X    return (cvfixnum((FIXTYPE)floor(getflonum(arg))));
  1793. X    else
  1794. X    xlbadtype(arg);
  1795. X}
  1796. X
  1797. X/* xceiling - built-in function 'ceiling' */
  1798. XLVAL xceiling()
  1799. X{
  1800. X    LVAL arg;
  1801. X
  1802. X    /* get the argument */
  1803. X    arg = xlgetarg();
  1804. X    xllastarg();
  1805. X
  1806. X    /* check its type */
  1807. X    if (fixp(arg))
  1808. X    return (arg);
  1809. X    else if (floatp(arg))
  1810. X    return (cvfixnum((FIXTYPE)ceil(getflonum(arg))));
  1811. X    else
  1812. X    xlbadtype(arg);
  1813. X}
  1814. X
  1815. X/* xround - built-in function 'round' */
  1816. XLVAL xround()
  1817. X{
  1818. X    FLOTYPE x,y,z;
  1819. X    LVAL arg;
  1820. X
  1821. X    /* get the argument */
  1822. X    arg = xlgetarg();
  1823. X    xllastarg();
  1824. X
  1825. X    /* check its type */
  1826. X    if (fixp(arg))
  1827. X    return (arg);
  1828. X    else if (floatp(arg)) {
  1829. X    x = getflonum(arg);
  1830. X    y = floor(x);
  1831. X    z = x - y;
  1832. X    if (z == 0.5) {
  1833. X        if (((FIXTYPE)y & 1) == 1)
  1834. X        y += 1.0;
  1835. X        return (cvfixnum((FIXTYPE)y));
  1836. X    }
  1837. X    else if (z < 0.5)
  1838. X        return (cvfixnum((FIXTYPE)y));
  1839. X    else
  1840. X        return (cvfixnum((FIXTYPE)(y + 1.0)));
  1841. X    }
  1842. X    else
  1843. X    xlbadtype(arg);
  1844. X}
  1845. X
  1846. X/* xtruncate - built-in function 'truncate' */
  1847. XLVAL xtruncate()
  1848. X{
  1849. X    LVAL arg;
  1850. X
  1851. X    /* get the argument */
  1852. X    arg = xlgetarg();
  1853. X    xllastarg();
  1854. X
  1855. X    /* check its type */
  1856. X    if (fixp(arg))
  1857. X    return (arg);
  1858. X    else if (floatp(arg))
  1859. X    return (cvfixnum((FIXTYPE)(getflonum(arg))));
  1860. X    else
  1861. X    xlbadtype(arg);
  1862. X}
  1863. X
  1864. X/* binary functions */
  1865. XLVAL xadd()                /* + */
  1866. X{
  1867. X    if (!moreargs())
  1868. X    return (cvfixnum((FIXTYPE)0));
  1869. X    return (binary('+'));
  1870. X}
  1871. XLVAL xmul()                /* * */
  1872. X{
  1873. X    if (!moreargs())
  1874. X    return (cvfixnum((FIXTYPE)1));
  1875. X    return (binary('*'));
  1876. X}
  1877. XLVAL xsub()    { return (binary('-')); } /* - */
  1878. XLVAL xdiv()    { return (binary('/')); } /* / */
  1879. XLVAL xquo()    { return (binary('Q')); } /* quotient */
  1880. XLVAL xrem()    { return (binary('R')); } /* remainder */
  1881. XLVAL xmin()    { return (binary('m')); } /* min */
  1882. XLVAL xmax()    { return (binary('M')); } /* max */
  1883. XLVAL xexpt()   { return (binary('E')); } /* expt */
  1884. XLVAL xlogand() { return (binary('&')); } /* logand */
  1885. XLVAL xlogior() { return (binary('|')); } /* logior */
  1886. XLVAL xlogxor() { return (binary('^')); } /* logxor */
  1887. X
  1888. X/* binary - handle binary operations */
  1889. XLOCAL LVAL binary(fcn)
  1890. X  int fcn;
  1891. X{
  1892. X    FIXTYPE ival,iarg;
  1893. X    FLOTYPE fval,farg;
  1894. X    LVAL arg;
  1895. X    int mode;
  1896. X
  1897. X    /* get the first argument */
  1898. X    arg = xlgetarg();
  1899. X
  1900. X    /* set the type of the first argument */
  1901. X    if (fixp(arg)) {
  1902. X    ival = getfixnum(arg);
  1903. X    mode = 'I';
  1904. X    }
  1905. X    else if (floatp(arg)) {
  1906. X    fval = getflonum(arg);
  1907. X    mode = 'F';
  1908. X    }
  1909. X    else
  1910. X    xlbadtype(arg);
  1911. X
  1912. X    /* treat a single argument as a special case */
  1913. X    if (!moreargs()) {
  1914. X    switch (fcn) {
  1915. X    case '-':
  1916. X        switch (mode) {
  1917. X        case 'I':
  1918. X        ival = -ival;
  1919. X        break;
  1920. X        case 'F':
  1921. X        fval = -fval;
  1922. X        break;
  1923. X        }
  1924. X        break;
  1925. X    case '/':
  1926. X        switch (mode) {
  1927. X        case 'I':
  1928. X        checkizero(ival);
  1929. X        if (ival != 1) {
  1930. X            fval = 1.0 / (FLOTYPE)ival;
  1931. X            mode = 'F';
  1932. X        }
  1933. X        break;
  1934. X        case 'F':
  1935. X        checkfzero(fval);
  1936. X        fval = 1.0 / fval;
  1937. X        break;
  1938. X        }
  1939. X    }
  1940. X    }
  1941. X
  1942. X    /* handle each remaining argument */
  1943. X    while (moreargs()) {
  1944. X
  1945. X    /* get the next argument */
  1946. X    arg = xlgetarg();
  1947. X
  1948. X    /* check its type */
  1949. X    if (fixp(arg)) {
  1950. X        switch (mode) {
  1951. X        case 'I':
  1952. X            iarg = getfixnum(arg);
  1953. X            break;
  1954. X        case 'F':
  1955. X            farg = (FLOTYPE)getfixnum(arg);
  1956. X        break;
  1957. X        }
  1958. X    }
  1959. X    else if (floatp(arg)) {
  1960. X        switch (mode) {
  1961. X        case 'I':
  1962. X            fval = (FLOTYPE)ival;
  1963. X        farg = getflonum(arg);
  1964. X        mode = 'F';
  1965. X        break;
  1966. X        case 'F':
  1967. X            farg = getflonum(arg);
  1968. X        break;
  1969. X        }
  1970. X    }
  1971. X    else
  1972. X        xlbadtype(arg);
  1973. X
  1974. X    /* accumulate the result value */
  1975. X    switch (mode) {
  1976. X    case 'I':
  1977. X        switch (fcn) {
  1978. X        case '+':    ival += iarg; break;
  1979. X        case '-':    ival -= iarg; break;
  1980. X        case '*':    ival *= iarg; break;
  1981. X        case '/':    checkizero(iarg);
  1982. X            if ((ival % iarg) == 0)        
  1983. X                ival /= iarg;
  1984. X            else {
  1985. X                fval = (FLOTYPE)ival;
  1986. X                farg = (FLOTYPE)iarg;
  1987. X                fval /= farg;
  1988. X                mode = 'F';
  1989. X            }
  1990. X            break;
  1991. X        case 'Q':    checkizero(iarg); ival /= iarg; break;
  1992. X        case 'R':    checkizero(iarg); ival %= iarg; break;
  1993. X        case 'M':    if (iarg > ival) ival = iarg; break;
  1994. X        case 'm':    if (iarg < ival) ival = iarg; break;
  1995. X        case 'E':    return (cvflonum((FLOTYPE)pow((FLOTYPE)ival,(FLOTYPE)iarg)));
  1996. X        case '&':    ival &= iarg; break;
  1997. X        case '|':    ival |= iarg; break;
  1998. X        case '^':    ival ^= iarg; break;
  1999. X        default:    badiop();
  2000. X        }
  2001. X        break;
  2002. X    case 'F':
  2003. X        switch (fcn) {
  2004. X        case '+':    fval += farg; break;
  2005. X        case '-':    fval -= farg; break;
  2006. X        case '*':    fval *= farg; break;
  2007. X        case '/':    checkfzero(farg); fval /= farg; break;
  2008. X        case 'M':    if (farg > fval) fval = farg; break;
  2009. X        case 'm':    if (farg < fval) fval = farg; break;
  2010. X        case 'E':    fval = pow(fval,farg); break;
  2011. X        default:    badfop();
  2012. X        }
  2013. X            break;
  2014. X    }
  2015. X    }
  2016. X
  2017. X    /* return the result */
  2018. X    switch (mode) {
  2019. X    case 'I':    return (cvfixnum(ival));
  2020. X    case 'F':    return (cvflonum(fval));
  2021. X    }
  2022. X}
  2023. X
  2024. X/* unary functions */
  2025. XLVAL xlognot() { return (unary('~')); } /* lognot */
  2026. XLVAL xabs()      { return (unary('A')); } /* abs */
  2027. XLVAL xadd1()     { return (unary('+')); } /* 1+ */
  2028. XLVAL xsub1()     { return (unary('-')); } /* -1+ */
  2029. XLVAL xsin()      { return (unary('S')); } /* sin */
  2030. XLVAL xcos()      { return (unary('C')); } /* cos */
  2031. XLVAL xtan()      { return (unary('T')); } /* tan */
  2032. XLVAL xasin()     { return (unary('s')); } /* asin */
  2033. XLVAL xacos()     { return (unary('c')); } /* acos */
  2034. XLVAL xxexp()     { return (unary('E')); } /* exp */
  2035. XLVAL xsqrt()     { return (unary('R')); } /* sqrt */
  2036. XLVAL xxlog()     { return (unary('L')); } /* log */
  2037. XLVAL xrandom()   { return (unary('?')); } /* random */
  2038. X
  2039. X/* unary - handle unary operations */
  2040. XLOCAL LVAL unary(fcn)
  2041. X  int fcn;
  2042. X{
  2043. X    FLOTYPE fval;
  2044. X    FIXTYPE ival;
  2045. X    LVAL arg;
  2046. X
  2047. X    /* get the argument */
  2048. X    arg = xlgetarg();
  2049. X    xllastarg();
  2050. X
  2051. X    /* check its type */
  2052. X    if (fixp(arg)) {
  2053. X    ival = getfixnum(arg);
  2054. X    switch (fcn) {
  2055. X    case '~':    ival = ~ival; break;
  2056. X    case 'A':    ival = (ival < 0 ? -ival : ival); break;
  2057. X    case '+':    ival++; break;
  2058. X    case '-':    ival--; break;
  2059. X    case 'S':    return (cvflonum((FLOTYPE)sin((FLOTYPE)ival)));
  2060. X    case 'C':    return (cvflonum((FLOTYPE)cos((FLOTYPE)ival)));
  2061. X    case 'T':    return (cvflonum((FLOTYPE)tan((FLOTYPE)ival)));
  2062. X    case 's':    return (cvflonum((FLOTYPE)asin((FLOTYPE)ival)));
  2063. X    case 'c':    return (cvflonum((FLOTYPE)acos((FLOTYPE)ival)));
  2064. X    case 't':    return (cvflonum((FLOTYPE)atan((FLOTYPE)ival)));
  2065. X    case 'E':    return (cvflonum((FLOTYPE)exp((FLOTYPE)ival)));
  2066. X    case 'L':    return (cvflonum((FLOTYPE)log((FLOTYPE)ival)));
  2067. X    case 'R':    checkineg(ival);
  2068. X            return (cvflonum((FLOTYPE)sqrt((FLOTYPE)ival)));
  2069. X    case '?':    ival = (FIXTYPE)osrand((int)ival); break;
  2070. X    default:    badiop();
  2071. X    }
  2072. X    return (cvfixnum(ival));
  2073. X    }
  2074. X    else if (floatp(arg)) {
  2075. X    fval = getflonum(arg);
  2076. X    switch (fcn) {
  2077. X    case 'A':    fval = (fval < 0.0 ? -fval : fval); break;
  2078. X    case '+':    fval += 1.0; break;
  2079. X    case '-':    fval -= 1.0; break;
  2080. X    case 'S':    fval = sin(fval); break;
  2081. X    case 'C':    fval = cos(fval); break;
  2082. X    case 'T':    fval = tan(fval); break;
  2083. X    case 's':    fval = asin(fval); break;
  2084. X    case 'c':    fval = acos(fval); break;
  2085. X    case 't':    fval = atan(fval); break;
  2086. X    case 'E':    fval = exp(fval); break;
  2087. X    case 'L':    fval = log(fval); break;
  2088. X    case 'R':    checkfneg(fval);
  2089. X            fval = sqrt(fval); break;
  2090. X    default:    badfop();
  2091. X    }
  2092. X    return (cvflonum(fval));
  2093. X    }
  2094. X    else
  2095. X    xlbadtype(arg);
  2096. X}
  2097. X
  2098. X/* xgcd - greatest common divisor */
  2099. XLVAL xgcd()
  2100. X{
  2101. X    FIXTYPE m,n,r;
  2102. X    LVAL arg;
  2103. X
  2104. X    if (!moreargs())            /* check for identity case */
  2105. X    return (cvfixnum((FIXTYPE)0));
  2106. X    arg = xlgafixnum();
  2107. X    n = getfixnum(arg);
  2108. X    if (n < (FIXTYPE)0) n = -n;        /* absolute value */
  2109. X    while (moreargs()) {
  2110. X    arg = xlgafixnum();
  2111. X    m = getfixnum(arg);
  2112. X    if (m < (FIXTYPE)0) m = -m;    /* absolute value */
  2113. X    for (;;) {            /* euclid's algorithm */
  2114. X        r = m % n;
  2115. X        if (r == (FIXTYPE)0)
  2116. X        break;
  2117. X        m = n;
  2118. X        n = r;
  2119. X    }
  2120. X    }
  2121. X    return (cvfixnum(n));
  2122. X}
  2123. X
  2124. X/* unary predicates */
  2125. XLVAL xnegativep() { return (predicate('-')); } /* negative? */
  2126. XLVAL xzerop()     { return (predicate('Z')); } /* zero? */
  2127. XLVAL xpositivep() { return (predicate('+')); } /* positive? */
  2128. XLVAL xevenp()     { return (predicate('E')); } /* even? */
  2129. XLVAL xoddp()      { return (predicate('O')); } /* odd? */
  2130. X
  2131. X/* predicate - handle a predicate function */
  2132. XLOCAL LVAL predicate(fcn)
  2133. X  int fcn;
  2134. X{
  2135. X    FLOTYPE fval;
  2136. X    FIXTYPE ival;
  2137. X    LVAL arg;
  2138. X
  2139. X    /* get the argument */
  2140. X    arg = xlgetarg();
  2141. X    xllastarg();
  2142. X
  2143. X    /* check the argument type */
  2144. X    if (fixp(arg)) {
  2145. X    ival = getfixnum(arg);
  2146. X    switch (fcn) {
  2147. X    case '-':    ival = (ival < 0); break;
  2148. X    case 'Z':    ival = (ival == 0); break;
  2149. X    case '+':    ival = (ival > 0); break;
  2150. X    case 'E':    ival = ((ival & 1) == 0); break;
  2151. X    case 'O':    ival = ((ival & 1) != 0); break;
  2152. X    default:    badiop();
  2153. X    }
  2154. X    }
  2155. X    else if (floatp(arg)) {
  2156. X    fval = getflonum(arg);
  2157. X    switch (fcn) {
  2158. X    case '-':    ival = (fval < 0); break;
  2159. X    case 'Z':    ival = (fval == 0); break;
  2160. X    case '+':    ival = (fval > 0); break;
  2161. X    default:    badfop();
  2162. X    }
  2163. X    }
  2164. X    else
  2165. X    xlbadtype(arg);
  2166. X
  2167. X    /* return the result value */
  2168. X    return (ival ? true : NIL);
  2169. X}
  2170. X
  2171. X/* comparison functions */
  2172. XLVAL xlss() { return (compare('<')); } /* < */
  2173. XLVAL xleq() { return (compare('L')); } /* <= */
  2174. XLVAL xeql() { return (compare('=')); } /* = */
  2175. XLVAL xgeq() { return (compare('G')); } /* >= */
  2176. XLVAL xgtr() { return (compare('>')); } /* > */
  2177. X
  2178. X/* compare - common compare function */
  2179. XLOCAL LVAL compare(fcn)
  2180. X  int fcn;
  2181. X{
  2182. X    FIXTYPE icmp,ival,iarg;
  2183. X    FLOTYPE fcmp,fval,farg;
  2184. X    LVAL arg;
  2185. X    int mode;
  2186. X
  2187. X    /* get the first argument */
  2188. X    arg = xlgetarg();
  2189. X
  2190. X    /* set the type of the first argument */
  2191. X    if (fixp(arg)) {
  2192. X    ival = getfixnum(arg);
  2193. X    mode = 'I';
  2194. X    }
  2195. X    else if (floatp(arg)) {
  2196. X    fval = getflonum(arg);
  2197. X    mode = 'F';
  2198. X    }
  2199. X    else
  2200. X    xlbadtype(arg);
  2201. X
  2202. X    /* handle each remaining argument */
  2203. X    for (icmp = TRUE; icmp && moreargs(); ival = iarg, fval = farg) {
  2204. X
  2205. X    /* get the next argument */
  2206. X    arg = xlgetarg();
  2207. X
  2208. X    /* check its type */
  2209. X    if (fixp(arg)) {
  2210. X        switch (mode) {
  2211. X        case 'I':
  2212. X            iarg = getfixnum(arg);
  2213. X            break;
  2214. X        case 'F':
  2215. X            farg = (FLOTYPE)getfixnum(arg);
  2216. X        break;
  2217. X        }
  2218. X    }
  2219. X    else if (floatp(arg)) {
  2220. X        switch (mode) {
  2221. X        case 'I':
  2222. X            fval = (FLOTYPE)ival;
  2223. X        farg = getflonum(arg);
  2224. X        mode = 'F';
  2225. X        break;
  2226. X        case 'F':
  2227. X            farg = getflonum(arg);
  2228. X        break;
  2229. X        }
  2230. X    }
  2231. X    else
  2232. X        xlbadtype(arg);
  2233. X
  2234. X    /* compute result of the compare */
  2235. X    switch (mode) {
  2236. X    case 'I':
  2237. X        icmp = ival - iarg;
  2238. X        switch (fcn) {
  2239. X        case '<':    icmp = (icmp < 0); break;
  2240. X        case 'L':    icmp = (icmp <= 0); break;
  2241. X        case '=':    icmp = (icmp == 0); break;
  2242. X        case 'G':    icmp = (icmp >= 0); break;
  2243. X        case '>':    icmp = (icmp > 0); break;
  2244. X        }
  2245. X        break;
  2246. X    case 'F':
  2247. X        fcmp = fval - farg;
  2248. X        switch (fcn) {
  2249. X        case '<':    icmp = (fcmp < 0.0); break;
  2250. X        case 'L':    icmp = (fcmp <= 0.0); break;
  2251. X        case '=':    icmp = (fcmp == 0.0); break;
  2252. X        case 'G':    icmp = (fcmp >= 0.0); break;
  2253. X        case '>':    icmp = (fcmp > 0.0); break;
  2254. X        }
  2255. X        break;
  2256. X    }
  2257. X    }
  2258. X
  2259. X    /* return the result */
  2260. X    return (icmp ? true : NIL);
  2261. X}
  2262. X
  2263. X/* toflotype - convert a lisp value to a floating point number */
  2264. XFLOTYPE toflotype(val)
  2265. X  LVAL val;
  2266. X{
  2267. X    /* must be a number for this to work */
  2268. X    switch (ntype(val)) {
  2269. X    case FIXNUM:    return ((FLOTYPE)getfixnum(val));
  2270. X    case FLONUM:    return (getflonum(val));
  2271. X    }
  2272. X}
  2273. X
  2274. X/* checkizero - check for integer division by zero */
  2275. Xcheckizero(iarg)
  2276. X  FIXTYPE iarg;
  2277. X{
  2278. X    if (iarg == 0)
  2279. X    xlfail("division by zero");
  2280. X}
  2281. X
  2282. X/* checkineg - check for square root of a negative number */
  2283. Xcheckineg(iarg)
  2284. X  FIXTYPE iarg;
  2285. X{
  2286. X    if (iarg < 0)
  2287. X    xlfail("square root of a negative number");
  2288. X}
  2289. X
  2290. X/* checkfzero - check for floating point division by zero */
  2291. Xcheckfzero(farg)
  2292. X  FLOTYPE farg;
  2293. X{
  2294. X    if (farg == 0.0)
  2295. X    xlfail("division by zero");
  2296. X}
  2297. X
  2298. X/* checkfneg - check for square root of a negative number */
  2299. Xcheckfneg(farg)
  2300. X  FLOTYPE farg;
  2301. X{
  2302. X    if (farg < 0.0)
  2303. X    xlfail("square root of a negative number");
  2304. X}
  2305. X
  2306. X/* badiop - bad integer operation */
  2307. XLOCAL badiop()
  2308. X{
  2309. X    xlfail("bad integer operation");
  2310. X}
  2311. X
  2312. X/* badfop - bad floating point operation */
  2313. XLOCAL badfop()
  2314. X{
  2315. X    xlfail("bad floating point operation");
  2316. X}
  2317. END_OF_FILE
  2318. if test 13437 -ne `wc -c <'Src/xsmath.c'`; then
  2319.     echo shar: \"'Src/xsmath.c'\" unpacked with wrong size!
  2320. fi
  2321. # end of 'Src/xsmath.c'
  2322. fi
  2323. echo shar: End of archive 3 \(of 7\).
  2324. cp /dev/null ark3isdone
  2325. MISSING=""
  2326. for I in 1 2 3 4 5 6 7 ; do
  2327.     if test ! -f ark${I}isdone ; then
  2328.     MISSING="${MISSING} ${I}"
  2329.     fi
  2330. done
  2331. if test "${MISSING}" = "" ; then
  2332.     echo You have unpacked all 7 archives.
  2333.     rm -f ark[1-9]isdone
  2334. else
  2335.     echo You still need to unpack the following archives:
  2336.     echo "        " ${MISSING}
  2337. fi
  2338. ##  End of shell archive.
  2339. exit 0
  2340. -- 
  2341. Mail submissions (sources or binaries) to <amiga@cs.odu.edu>.
  2342. Mail comments to the moderator at <amiga-request@cs.odu.edu>.
  2343. Post requests for sources, and general discussion to comp.sys.amiga.
  2344.